<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" />
<title>表单 - 订单</title>
<link rel="icon" href="../../../favicon.ico" type="image/ico">
<link href="../../../css/bootstrap.min.css" rel="stylesheet">
<link href="../../../css/materialdesignicons.min.css" rel="stylesheet">
<link href="../../../css/style.min.css" rel="stylesheet">
</head>
  
<body>
<div class="container-fluid p-t-15">
  
  <div class="row">
    <div class="col-lg-12">
      <div class="card">
        <div class="card-body">
          
          <form class="site-form">
          	<div class="form-group">
          		<label for="ordername">订单名称</label>
          		<input type="text" class="form-control" name="ordername" id="ordername"/>
          	</div>
          	
          	<div class="form-group">
          		<label for="order_detail">订单明细</label>
          		<select class="form-control" id="order_detail" name="order_detail" size="1">
          			<option value="0">请选择</option>
          			<option value="1">选项 #1</option>
          			<option value="2">选项 #2</option>
          			<option value="3">选项 #3</option>
          		</select>
          	</div> 
          	
          	<div class="form-group">
          		<label for="order_price">订单金额</label>
          		<input type="text" class="form-control" name="order_price" id="order_price"/>
          	</div>
					
						
            <button id="submit2" class="btn btn-primary">保存</button>

            </div>
          </form>
          
        </div>
      </div>
    </div>
    
  </div>
  
</div>

<script type="text/javascript" src="../../../js/jquery.min.js"></script>
<script>
			var orderId = ";"
			$(function() {
				var url = location.search //获取url中"?"符后的字串 ('?modFlag=business&role=1')
				var theRequest = new Object()
				if (url.indexOf('?') != -1) {
					var str = url.substr(1) //substr()方法返回从参数值开始到结束的字符串；
					var strs = str.split('&')
					for (var i = 0; i < strs.length; i++) {
						theRequest[strs[i].split('=')[0]] = strs[i].split('=')[1]
					}
					orderId = theRequest.orderId;
					$(" input[ name='ordername' ] ").val(decodeURI(theRequest.orderName));
					 $("#order_detail").val(theRequest.orderDetail);
					 $(" input[ name='order_price' ] ").val(theRequest.orderPrice);

				}
			});
			$("#submit2").click(function() {
				console.log(orderId);
				var orderName = $(" input[ name='ordername' ] ").val();
				var orderDetail = $("#order_detail").val();
				var orderPrice = $(" input[ name='order_price' ] ").val();	
				$.ajax({
					url: "http://www.oa.com/order/add",
					type: "post",
					data: {
						"orderName": orderName,
						"orderPrice": orderPrice,
						"orderDetail": orderDetail,
					},
					dataType: "json",
					async: false,
					success: function(result) {
						//result是服务端返回的数据
						if (result.status == 200) {
							alert("添加成功！")
							location.href = "order_list.html";
						} else {
							alert("添加失败");
						}
					},
					error: function() {
						alert("请求失败!");
					}
				});

			})
		</script>
</body>
</html>